var jsonTree = function (data,config) {
  //1
  var id = config.id || 'id',
    pid = config.pid || 'pid',
    children = config.children || 'children';
  var idMap = [],
    jsonTree = [];

  //2
  data.forEach(function(v){
    idMap[v[id]] = v;
  });

  //3
  data.forEach(function(v){
    var parent = idMap[v[pid]];
    if(parent) {
      !parent[children] && (parent[children] = []);
      parent[children].push(v);
    } else {
      jsonTree.push(v);
    }
  });

  return jsonTree;
};
